home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / PROGS / GLE / mainsimple.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  1.8 KB  |  83 lines

  1.  
  2. /* 
  3.  * FUNCTION:
  4.  * very minimal "main()" for GL demos.
  5.  *
  6.  * HISTORY:
  7.  * Linas Vepstas March 1995
  8.  */
  9.  
  10. /* required include files */
  11. #include <stdlib.h>
  12. #include <GL/glut.h>
  13.  
  14. extern void DrawStuff (void);
  15. extern void InitStuff (void);
  16.  
  17. float lastx=0;
  18. float lasty=0;
  19.  
  20. /* get notified of mouse motions */
  21. void MouseMotion (int x, int y)
  22. {
  23.    lastx = x;
  24.    lasty = y;
  25.    glutPostRedisplay ();
  26. }
  27.  
  28. /* ARGSUSED */
  29. void JoinStyle (int msg) 
  30. {
  31.     exit (0);
  32. }
  33.  
  34. /* set up a light */
  35. GLfloat lightOnePosition[] = {40.0, 40, 100.0, 0.0};
  36. GLfloat lightOneColor[] = {0.99, 0.99, 0.99, 1.0}; 
  37.  
  38. GLfloat lightTwoPosition[] = {-40.0, 40, 100.0, 0.0};
  39. GLfloat lightTwoColor[] = {0.99, 0.99, 0.99, 1.0}; 
  40.  
  41. int
  42. main (int argc, char * argv[]) {
  43.  
  44.    /* initialize glut */
  45.    glutInit (&argc, argv);
  46.    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  47.    glutCreateWindow ("basic demo");
  48.    glutDisplayFunc (DrawStuff);
  49.    glutMotionFunc (MouseMotion);
  50.  
  51.    /* create popup menu */
  52.    glutCreateMenu (JoinStyle);
  53.    glutAddMenuEntry ("Exit", 99);
  54.    glutAttachMenu (GLUT_MIDDLE_BUTTON);
  55.  
  56.    /* initialize GL */
  57.    glClearDepth (1.0);
  58.    glEnable (GL_DEPTH_TEST);
  59.    glClearColor (0.0, 0.0, 0.0, 0.0);
  60.    glShadeModel (GL_SMOOTH);
  61.  
  62.    glMatrixMode (GL_PROJECTION);
  63.    /* roughly, measured in centimeters */
  64.    glFrustum (-9.0, 9.0, -9.0, 9.0, 50.0, 150.0);
  65.    glMatrixMode(GL_MODELVIEW);
  66.  
  67.    /* initialize lighting */
  68.    glLightfv (GL_LIGHT0, GL_POSITION, lightOnePosition);
  69.    glLightfv (GL_LIGHT0, GL_DIFFUSE, lightOneColor);
  70.    glEnable (GL_LIGHT0);
  71.    glLightfv (GL_LIGHT1, GL_POSITION, lightTwoPosition);
  72.    glLightfv (GL_LIGHT1, GL_DIFFUSE, lightTwoColor);
  73.    glEnable (GL_LIGHT1);
  74.    glEnable (GL_LIGHTING);
  75.    glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE);
  76.    glEnable (GL_COLOR_MATERIAL);
  77.  
  78.    InitStuff ();
  79.  
  80.    glutMainLoop ();
  81.    return 0;             /* ANSI C requires main to return int. */
  82. }
  83.